package com.exam.controller;
import com.exam.entity.Admin;
import com.exam.entity.ApiResult;
import com.exam.serviceimpl.AdminServiceImpl;
import com.exam.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
public class AdminController {
    @Autowired
    private AdminServiceImpl adminService;
        @GetMapping("/admins")
    public ApiResult findAll() {
        System.out.println("查询全部");
        return ApiResultHandler.success(adminService.findAll());
    }
    @GetMapping("/admin/{adminId}")
    public ApiResult findById(@PathVariable("adminId") Integer adminId) {
        System.out.println("根据ID查找");
        return ApiResultHandler.success(adminService.findById(adminId));
    }
    @DeleteMapping("/admin/{adminId}")
    public ApiResult deleteById(@PathVariable("adminId") Integer adminId) {
        adminService.deleteById(adminId);
        return ApiResultHandler.success();
    }
    @PutMapping("/admin/{adminId}")
    public ApiResult update(@PathVariable("adminId") Integer adminId, Admin admin) {
        return ApiResultHandler.success(adminService.update(admin));
    }
    //原来代码是注释掉的内容
//    @PostMapping("/admin")
    @GetMapping("/admin")
    public ApiResult add(Admin admin) {
        return ApiResultHandler.success(adminService.add(admin));
    }
    @PutMapping("/adminPWD")
    public ApiResult updatePwd(@RequestBody Admin admin) {
        adminService.updatePwd(admin);
        return ApiResultHandler.buildApiResult(200, "密码更新成功", null);
    }
}
